"""
@author: 江同学呀
@file: numeric_field.py
@date: 2024/7/26 0:19
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/number.html

    Numeric types, such as long and double, used to express amounts.
    用于表示金额的数值类型，例如 long 和 double 。
"""
from abc import ABC
from typing import Type, Union, Dict, Any

from espc.common.field_common import TimeSeriesMetric
from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_numeric_field import _BaseNumericField
from espc.orm.model.mapping.field.field_attribute import BoostAttribute, DocValuesAttribute, StoreAttribute, IndexAttribute, \
    NullValueAttribute, ScriptAttribute, OnScriptErrorAttribute, MetaAttribute, TimeSeriesDimensionAttribute, \
    CoerceAttribute, IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ScalingFactorAttribute
from espc.utils.build_add_attr import build_add_attr


class LongField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    有符号的64位整数 字段

    A signed 64-bit integer with a minimum value of -263 and a maximum value of 263-1.
    一个有符号的 64 位整数，最小值为 -263 ，最大值为 263-1 。
    """
    _field_type: str = "long"

    def __init__(
            self, field_name: str = None, value: int = None, default: int = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(LongField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            index=index, store=store, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["LongField"]) -> Union["LongField", int]:
        return super(LongField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: int):
        super(LongField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, value: int):
        self._value: int = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class IntegerField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    有符号的32位整数 字段

    A signed 32-bit integer with a minimum value of -231 and a maximum value of 231-1.
    一个有符号的 32 位整数，最小值为 -231 ，最大值为 231-1 。
    """
    _field_type: str = "integer"

    def __init__(
            self, field_name: str = None, value: int = None, default: int = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(IntegerField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["IntegerField"]) -> Union["IntegerField", int]:
        return super(IntegerField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: int):
        super(IntegerField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, value: int):
        self._value: int = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class ShortField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    有符号的16位整数 字段

    A signed 16-bit integer with a minimum value of -32,768 and a maximum value of 32,767.
    一个有符号的 16 位整数，最小值为 -32,768 ，最大值为 32,767 。
    """
    _field_type: str = "short"

    def __init__(
            self, field_name: str = None, value: int = None, default: int = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(ShortField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["ShortField"]) -> Union["ShortField", int]:
        return super(ShortField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: int):
        super(ShortField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, value: int):
        self._value: int = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class ByteField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    有符号的8位整数 字段

    A signed 8-bit integer with a minimum value of -128 and a maximum value of 127.
    一个有符号的 8 位整数，最小值为 ，最大值为 -128 127 。
    """
    _field_type: str = "byte"

    def __init__(
            self, field_name: str = None, value: int = None, default: int = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(ByteField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["ByteField"]) -> Union["ByteField", int]:
        return super(ByteField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: int):
        super(ByteField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, value: int):
        self._value: int = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class DoubleField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    双精度64位IEEE754浮点数 字段

    A double-precision 64-bit IEEE 754 floating point number, restricted to finite values.
    双精度 64 位 IEEE 754 浮点数，限制为有限值。
    """
    _field_type: str = "double"

    def __init__(
            self, field_name: str = None, value: float = None, default: float = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(DoubleField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["DoubleField"]) -> Union["DoubleField", float]:
        return super(DoubleField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: float):
        super(DoubleField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> float:
        return self._value

    @value.setter
    def value(self, value: float):
        self._value: float = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class FloatField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    单精度32位IEEE754浮点数 字段

    A single-precision 32-bit IEEE 754 floating point number, restricted to finite values.
    单精度 32 位 IEEE 754 浮点数，限制为有限值。
    """
    _field_type: str = "float"

    def __init__(
            self, field_name: str = None, value: float = None, default: float = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(FloatField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["FloatField"]) -> Union["FloatField", float]:
        return super(FloatField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: float):
        super(FloatField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> float:
        return self._value

    @value.setter
    def value(self, value: float):
        self._value: float = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class HalfFloatField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    单精度32位IEEE754浮点数 字段

    A half-precision 16-bit IEEE 754 floating point number, restricted to finite values.
    半精度 16 位 IEEE 754 浮点数，限制为有限值。
    """
    _field_type: str = "half_float"

    def __init__(
            self, field_name: str = None, value: float = None, default: float = None, boost: float = None,
            doc_values: bool = None, ignore_malformed: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(HalfFloatField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce,
            store=store, index=index, ignore_malformed=ignore_malformed, null_value=null_value, meta=meta,
            on_script_error=on_script_error, script=script, time_series_dimension=time_series_dimension,
            time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["HalfFloatField"]) -> Union["HalfFloatField", float]:
        return super(HalfFloatField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: float):
        super(HalfFloatField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> float:
        return self._value

    @value.setter
    def value(self, value: float):
        self._value: float = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class ScaledFloatField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ScalingFactorAttribute, ABC
):
    """
    浮点数 字段

    A floating point number that is backed by a long, scaled by a fixed double scaling factor.
    一个浮点数，由一个长型支撑，由固定的双倍比例因子缩放。
    """
    _field_type: str = "scaled_float"

    def __init__(
            self, field_name: str = None, value: float = None, default: float = None, boost: float = None,
            ignore_malformed: bool = None, doc_values: bool = None, store: bool = None, index: bool = None,
            null_value: Any = None, meta: Dict = None, coerce: bool = None, on_script_error: str = None,
            script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None, scaling_factor: float = None,
    ):
        super(ScaledFloatField, self).__init__(
            field_name=field_name, value=value, default=default, boost=boost, doc_values=doc_values, store=store,
            index=index, coerce=coerce, time_series_dimension=time_series_dimension, null_value=null_value,
            on_script_error=on_script_error, script=script, meta=meta, time_series_metric=time_series_metric,
            scaling_factor=scaling_factor, ignore_malformed=ignore_malformed,
        )
        return

    def __get__(self, instance: _Base, owner: Type["ScaledFloatField"]) -> Union["ScaledFloatField", float]:
        return super(ScaledFloatField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: float):
        super(ScaledFloatField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> float:
        return self._value

    @value.setter
    def value(self, value: float):
        self._value: float = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping


class UnsignedLongField(
    _BaseNumericField, BoostAttribute, DocValuesAttribute, CoerceAttribute, StoreAttribute, IndexAttribute,
    NullValueAttribute, MetaAttribute, OnScriptErrorAttribute, ScriptAttribute, TimeSeriesDimensionAttribute,
    IgnoreMalformedAttribute, TimeSeriesMetricAttribute, ABC
):
    """
    无符号64位整数 字段

    An unsigned 64-bit integer with a minimum value of 0 and a maximum value of 264-1.
    最小值为 0 且最大值为 264-1 的无符号 64 位整数。
    """
    _field_type: str = "unsigned_long"

    def __init__(
            self, value: int = None, default: int = None, boost: float = None, doc_values: bool = None, ignore_malformed: bool = None,
            store: bool = None, index: bool = None, null_value: Any = None, meta: Dict = None, coerce: bool = None,
            on_script_error: str = None, script: str = None, time_series_dimension: bool = None,
            time_series_metric: Union[str, TimeSeriesMetric] = None,
    ):
        super(UnsignedLongField, self).__init__(
            value=value, default=default, boost=boost, doc_values=doc_values, coerce=coerce, store=store, index=index,
            ignore_malformed=ignore_malformed, null_value=null_value, meta=meta, on_script_error=on_script_error,
            script=script, time_series_dimension=time_series_dimension, time_series_metric=time_series_metric,
        )
        return

    def __get__(self, instance: _Base, owner: Type["UnsignedLongField"]) -> Union["UnsignedLongField", int]:
        return super(UnsignedLongField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: int):
        super(UnsignedLongField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, value: int):
        self._value: int = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type,
        }
        return mapping





